{template 'tpl_header'}

<div class="weui-panel weui-panel_access">
    <div class="weui-cells" style="margin-top: 0;font-size: 14px;">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>选择日期</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        <div class="weui-cell weui-cell_access">
            <div class="weui-cell__hd"><label for="date" class="weui-label">出发日期</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请选择出发日期" id="date" type="text">
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
        <div class="weui-cell weui-cell_access">
            <div class="weui-cell__hd"><label for="date" class="weui-label">结束日期</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" placeholder="请选择返回日期" id="date2" type="text">
            </div>
            <div class="weui-cell__ft">
            </div>
        </div>
    </div>
</div>

<div class="weui-panel weui-panel_access">
    <div class="weui-cells" style="margin-top: 0;font-size: 14px;">
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <p>选择被保人</p>
            </div>
            <div class="weui-cell__ft">

            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">成年人</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft">
                <div class="weui-count">
                    <a class="weui-count__btn weui-count__decrease"></a>
                    <input class="weui-count__number" name="adult_number" type="number" value="0"/>
                    <a class="weui-count__btn weui-count__increase"></a>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">未成年人</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft">
                <div class="weui-count">
                    <a class="weui-count__btn weui-count__decrease"></a>
                    <input class="weui-count__number" name="child_number" type="number" value="0"/>
                    <a class="weui-count__btn weui-count__increase"></a>
                </div>
            </div>
        </div>
    </div>
</div>

<div class='insurance_btn_row'>
    <a href="javascript:;" id="search" class="weui-btn weui-btn_primary">立即选保险</a>
</div>

<div class="weui-tabbar">
    <a href="{php echo $this->createMobileUrl('list'); }" class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <i class="iconfont icon-zhixing"></i>
        </div>
        <p class="weui-tabbar__label">知行</p>
    </a>
    <a href="{php echo $this->createMobileUrl('line'); }" class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <i class="iconfont icon-xianlu"></i>
        </div>
        <p class="weui-tabbar__label">线路</p>
    </a>
    <a href="javascript:;" class="weui-tabbar__item weui-bar__item--on">
        <div class="weui-tabbar__icon">
            <i class="iconfont icon-baoxianxiaoshou1"></i>
        </div>
        <p class="weui-tabbar__label">保险</p>
    </a>
    <a href="{php echo $this->createMobileUrl('me'); }" class="weui-tabbar__item">
        <div class="weui-tabbar__icon">
            <i class="iconfont icon-account"></i>
        </div>
        <p class="weui-tabbar__label">我</p>
    </a>
</div>

{template 'tpl_footer'}
<script>
    var MAX = 99, MIN = 0;
    $('.weui-count__decrease').click(function (e) {
        var $input = $(e.currentTarget).parent().find('.weui-count__number');
        var number = parseInt($input.val() || "0") - 1
        if (number < MIN) number = MIN;
        $input.val(number)
    });
    $('.weui-count__increase').click(function (e) {
        var $input = $(e.currentTarget).parent().find('.weui-count__number');
        var number = parseInt($input.val() || "0") + 1
        if (number > MAX) number = MAX;
        $input.val(number)
    });
    $("#date").calendar({
        minDate: new Date() - (3600 * 24 * 1000),
        dateFormat: 'yyyy/mm/dd'  // 自定义格式的时候，不能通过 input 的value属性赋值 '2016年12月12日' 来定义初始值，这样会导致无法解析初始值而报错。只能通过js中设置 value 的形式来赋值，并且需要按标准形式赋值（yyyy-mm-dd 或者时间戳)
    });
    $("#date2").calendar({
        minDate: new Date() - (3600 * 24 * 1000),
        dateFormat: 'yyyy/mm/dd'  // 自定义格式的时候，不能通过 input 的value属性赋值 '2016年12月12日' 来定义初始值，这样会导致无法解析初始值而报错。只能通过js中设置 value 的形式来赋值，并且需要按标准形式赋值（yyyy-mm-dd 或者时间戳)
    });

    $(function () {
        $('#search').click(function () {
            var start_day = $('#date').val();
            var finish_day = $('#date2').val();
            var adult_number = $('input[name="adult_number"]').val();
            var child_number = $('input[name="child_number"]').val();

            if (start_day == '') {
                $.toast('请选择出发日期', "cancel");
                return false;
            }
            if (finish_day == '') {
                $.toast('请选择返回日期', "cancel");
                return false;
            }
            if ((adult_number == 0 || adult_number == '') && (child_number == 0 || child_number == '')) {
                $.toast('请选择被保人', "cancel");
                return false;
            }

            var url = "{php echo url('entry', array('m' => 'vj_bontrip','do' => 'insurance','op' => 'list'),true);}";
            url += "&adult_number=" + adult_number + "&child_number=" + child_number + "&start_day=" + start_day + "&finish_day=" + finish_day;
            window.location.href = url;
        });
    });
</script>